let contentTitle=document.getElementsByClassName("contentTitle")[0];
let sendTime=document.getElementsByClassName("sendTime")[0];
let contentBox=document.getElementsByClassName("contentBox")[0];
let contentManagement=document.getElementsByClassName("contentManagement")[0];
//遍历我的收藏
myCollect();
function myCollect() {
    $.ajax({
        url: "../collection/findBloggerCollection",
        type: "post",
        // datatype: "json",
        data: {
            userid: sessionStorage.getItem("id"),
        },
        success: function (data) {
            // console.log("aaa")
            console.log(data);
            if (data.msg == "查询成功") {
                for (let i = 0; i < data.data.length; i++) {
                    let contentManagement_box = document.createElement('div');
                    contentManagement_box.className = "contentManagement_box";
                    //let contentManagementBox=document.getElementsByClassName("contentManagement_box")
                    contentManagement.appendChild(contentManagement_box);
                    let contentTitle = document.createElement("div");
                    contentTitle.className = "contentTitle";
                    let contentData = document.createElement("div");
                    contentData.className = "contentData";
                    contentManagement_box.appendChild(contentTitle);
                    contentManagement_box.appendChild(contentData);
                    contentData.innerHTML = "取消收藏";
                    contentTitle.innerHTML = data.data[i].blogname;
                    let contentdata = document.getElementsByClassName("contentData");
                    contentdata[i].onclick = function () {
                        var Confirm = confirm("确定取消收藏"+data.data[i].blogname+"吗");
                        if (Confirm == true) {
                            $.ajax({
                                url: "../collection/Collection",
                                type: "get",
                                data: {
                                    blogid: data.data[i].blogid,
                                    userid: sessionStorage.getItem("id"),
                                },
                                success: function (data) {
                                    console.log(data);
                                    if (data.msg == "取消收藏成功") {
                                        alert("取消收藏成功！")
                                        //删除所有遍历出来的数据
                                        let child = contentManagement.lastElementChild;
                                        while (child) {
                                            contentManagement.removeChild(child);
                                            child = contentManagement.lastElementChild;
                                        }
                                        //调用函数重新遍历
                                        myCollect();
                                    } else {
                                        console.log(data);
                                    }

                                }
                            })
                        } else {

                        }
                    }
                }
            }
        },
    })
}
